#include <semaphore.h>
#include <sys/types.h>
#include <dirent.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>

// 线程私有的全局变量，仅在某个线程中有效，但却可以跨多个函数访问
__thread int POD;

void* task1(void* arg)
{
    POD = 1;
    printf("thread1 POD %d\n", POD);
    sleep(1);
    printf("thread1 POD %d\n", POD);
}

void* task2(void* arg)
{
    POD = 2;
    printf("thread2 POD %d\n", POD);
    sleep(2);
    printf("thread2 POD %d\n", POD);
}

int main(int argc, char* argv[])
{
    pthread_t thr1, thr2;
    pthread_create(&thr1,NULL,task1,NULL);
    pthread_create(&thr2,NULL,task2,NULL);
    pthread_join(thr1, NULL);
    pthread_join(thr2, NULL);
    printf("main thread exit...\n");
    return 0;
}
